# -*- coding: utf-8 -*-
"""
@Time ：2021/4/6 20:58 
@Auth ： Mr. William 1052949192
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：手Q APP的测试
"""
# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python
import time

from appium import webdriver

caps = {}
caps["platformName"] = "Android"
caps["deviceName"] = "3e5d55a"
caps["appPackage"] = "com.tencent.mobileqq"
caps["appActivity"] = ".activity.SplashActivity"
caps["noReset"] = True
caps["unicodeKeyboard"] = True
caps["resetKeyboard"] = True
caps["automationName"] = "uiautomator1"
# caps["chromedriverExecutable"] = "E:\\Appium-1.9\\resources\\app\\node_modules\\appium\\node_modules\\appium-chromedriver\\chromedriver\\win\\chromedriver.exe"
caps["ensureWebviewsHavePages"] = True

# 需要连接appium，然后才能回放
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", caps)
# 添加隐式等待
driver.implicitly_wait(10)

el1 = driver.find_element_by_accessibility_id("请输入QQ号码或手机或邮箱")
el1.clear()
el1.send_keys("3599292078")
el2 = driver.find_element_by_accessibility_id("密码 安全")
el2.click()
el2.clear()
el2.send_keys("xiaobao168")
el3 = driver.find_element_by_accessibility_id("登 录")
el3.click()

# 加好友
el3 = driver.find_element_by_accessibility_id("搜索")
el3.click()
el4 = driver.find_element_by_id("com.tencent.mobileqq:id/et_search_keyword")
el4.send_keys("632232258")
el5 = driver.find_element_by_id("com.tencent.mobileqq:id/ikf")
el5.click()
els1 = driver.find_elements_by_xpath("//*[@text=\"【特斯汀】课程顾问-卡卡\"]")
els1[0].click()
time.sleep(1)
driver.back()
time.sleep(1)
driver.back()
time.sleep(1)
driver.back()
time.sleep(1)


# 退出登录
el4 = driver.find_element_by_accessibility_id("帐户及设置")
el4.click()
el5 = driver.find_element_by_accessibility_id("设置")
el5.click()
el6 = driver.find_element_by_id("com.tencent.mobileqq:id/account_switch")
el6.click()
el7 = driver.find_element_by_accessibility_id("退出当前帐号按钮")
el7.click()

els3 = driver.find_elements_by_xpath("//*[@text=\"退出登录\"]")
els3[0].click()
el8 = driver.find_element_by_id("com.tencent.mobileqq:id/dialogRightBtn")
el8.click()

driver.quit()


